<template>
    <div>
        <div>
            <el-form :model="filterForm" label-width="70px">
                <el-row>
                    <el-col :span="6">
                        <el-form-item label="病理编号">
                            <el-input
                                v-model="filterForm.pathologyId"
                                placeholder="请输入病理编号"
                                class="input-form"
                                size="mini"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="评价状态">
                            <el-select
                                placeholder="请选择评价状态"
                                v-model="filterForm.isEvaluate"
                                clearable
                                class="picker-form"
                                size="mini"
                            >
                                <el-option
                                    v-for="item in isEvaluateList"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="2" class="col-button-top">
                        <el-button
                            size="mini"
                            :loading="assessmentTable.isLoading"
                            @click="getPages"
                            type="primary"
                            >搜索</el-button
                        >
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <el-row class="col-button-top" style="text-align: center"></el-row>
        <el-row class="col-button-top">
            <base-table
                v-loading="assessmentTable.isLoading"
                :header="assessmentTable.header"
                :operation="assessmentTable.operation"
                :data="assessmentTable.data"
                :pageInfo="assessmentTable.pageInfo"
                :cellStyleFunc="diagnosisTableCellStyleFunc"
                @handleClick="diagnosisTableButtonClick"
                @pageJumpTo="diagnosisTablePageJumpTo"
                @sizeChange="diagnosisTableSizeChange"
                tooltip-effect="“dark”"
            >
                <template #nameSlot>
                    <span>蓝色:切片不足;黑色:切片正常;红色:切片过多;</span>
                </template>
            </base-table>
        </el-row>
    </div>
</template>

<script>
import BaseTable from '@templates/components/BaseTable';
import { isEvaluateList } from '@/client/consts/enum';
import { itemsPerPage } from '@/client/libs/util';

export default {
    name: 'AiEvaluation',
    components: {
        BaseTable,
    },
    data() {
        return {
            imageServiceURL: process.env.ImageServiceURL,
            isEvaluateList: isEvaluateList,
            filterForm: {
                pathologyId: '',
                page: 0,
                isEvaluate: '', //评价状态  默认未评价
                size: itemsPerPage.get(),
            },
            assessmentTable: {
                isLoading: false,
                data: [],
                header: [
                    {
                        label: '病理编号',
                        prop: 'pathologyId',
                        width: '107',
                    },
                    {
                        label: '评价状态',
                        prop: 'isEvaluateStatus',
                        width: '107',
                    },
                    {
                        label: '诊断状态',
                        prop: 'currentLevelLabel',
                        width: '107',
                    },
                    {
                        label: '冰冻',
                        prop: 'freezeTypeName',
                        width: '80',
                    },
                    {
                        label: '标本类型',
                        prop: 'specimenTypeName',
                        width: '107',
                    },
                    {
                        label: '检查类型',
                        prop: 'checkCategoryName',
                        width: '107',
                    },
                    {
                        label: '诊断组',
                        prop: 'subspecialtyTypeName',
                        width: '107',
                    },
                    {
                        label: '取材部位',
                        prop: 'sampleBody',
                        width: '107',
                    },
                    {
                        label: '患者姓名',
                        prop: 'name',
                        width: '107',
                    },
                    {
                        label: '性别',
                        prop: 'sex',
                        width: '80',
                    },
                    {
                        label: '年龄',
                        prop: 'age',
                        width: '80',
                    },
                    {
                        label: '切片质量',
                        prop: 'biopsyQuality',
                        width: '107',
                    },
                    {
                        label: '清晰度',
                        prop: 'scanDefinition',
                        width: '107',
                    },
                    {
                        label: '送检科室',
                        prop: 'sendDepartment',
                        width: '107',
                    },
                    {
                        label: '送检医生',
                        prop: 'sendDoctor',
                        width: '107',
                    },
                    {
                        label: '扫描日期',
                        prop: 'biopsyScanTime',
                        width: '136',
                    },
                    {
                        label: '扫描批次',
                        prop: 'biopsyHistoryId',
                        width: '107',
                    },
                ],

                operation: [
                    {
                        label: '评价',
                        functionKey: 'sliceAssessClick',
                    },
                ],
                pageInfo: {
                    page: 1,
                    size: itemsPerPage.get(),
                    total: 0,
                },
            },
            dictRequestMap: [
                {
                    code: 'sliceUses',
                    arrayKey: 'sliceUsesList',
                },
            ],
        };
    },
    mounted() {
        this.getPages();
    },
    methods: {
        diagnosisTableCellStyleFunc({ row, column }) {
            const baseStyle = {
                padding: '3px 0',
                'border-right': '1px solid #ffffff',
                'font-size': '14px',
            };
            switch (column.label) {
                case '性别':
                    if (row.sex === '女性') {
                        baseStyle.color = 'red';
                    }
                    if (row.sex === '男性') {
                        baseStyle.color = 'blue';
                    }
                    break;
                case '倒计时':
                    if (row.deadlineTime < 48 * 3600 * 1000) {
                        baseStyle.color = 'red';
                    } else {
                        baseStyle.color = 'green';
                    }
                    break;
                case '已扫/总':
                    if (row.biopsyCheckColor == '#10a1df') {
                        baseStyle.color = '#10a1df';
                    } else if (row.biopsyCheckColor == 'red') {
                        baseStyle.color = 'red';
                    } else {
                        baseStyle.color = '#666666';
                    }
                    break;
            }
            return baseStyle;
        },
        sliceAssessClick(row) {
            if (row.biopsyCount === 0) {
                this.$message.info('此切片需重扫还未重扫完成！！！');
            } else {
                sessionStorage.setItem('pDiagnosisType', null);
                sessionStorage.setItem('pathologyId', row.pathologyId);
                const { state } = this.$store;
                const { href } = this.$router.resolve({
                    name: 'copyViewer',
                    path: '/copy-Viewer',
                    query: {
                        fileName: row.newFilename,
                        originFilename: row.originFilename,
                        pathologyId: row.pathologyId,
                        biopsyId: row.id,
                        authorization: this.$store.state.authorization,
                        userId: state.user.id,
                        isEvaluateValue: this.filterForm.isEvaluate,
                        queryPathologyId: this.filterForm.pathologyId,
                    },
                });
                const width = window.screen.availWidth + 10;
                const height = window.screen.availHeight + 10;
                window.open(
                    href,
                    'doctorWorkstation',
                    `location=no,width=${width},height=${height}`
                );
            }
        },
        diagnosisTableButtonClick(functionKey, row) {
            this[functionKey](row);
        },
        diagnosisTablePageJumpTo(val) {
            this.assessmentTable.pageInfo.page = val;
            // 为 diagnosisTable.data 赋值相应页上新数据
            this.getPages();
        },
        diagnosisTableSizeChange(val) {
            this.assessmentTable.pageInfo.size = val;
            // 为 diagnosisTable.data 赋值相应数据量新数据
            this.getPages();
        },
        // 默认主页page页面
        async getPages() {
            const form = {
                page: this.assessmentTable.pageInfo.page - 1,
                size: this.assessmentTable.pageInfo.size,
                isEvaluate: this.filterForm.isEvaluate, //评价状态
                queryPathologyId: this.filterForm.pathologyId,
            };
            this.assessmentTable.isLoading = true;
            await this.$axios({
                url: `/PROXY-Remote/biopsy/findAllBiopsy/doctorAiEvaluate`,
                method: 'POST',
                data: form,
            }).then((res) => {
                // 请求失败
                if (res.data.code !== 200) {
                    throw new Error(res.data);
                }
                this.assessmentTable.data = [];
                res.data.data.forEach((t) => {
                    this.assessmentTable.data.push({
                        index: this.assessmentTable.data.length,
                        id: t.id,
                        currentLevelLabel:
                            t.currentLevelLabel +
                            this.getComposeValue(t.diagnosisType),
                        pathologyId: t.pathologyId,
                        name: t.name,
                        sendDoctor: t.sendDoctor,
                        age: t.age == null ? '' : t.age + t.ageUnitName,
                        sex: t.sexName,
                        sendDepartment: t.sendDepartment,
                        sampleBody: t.sampleBody,
                        sampleOrganName: t.sampleOrganName,
                        biopsyHistoryId: t.biopsyHistoryId,
                        biopsyScanTime: t.biopsyScanTime,
                        freezeTypeName: t.freezeTypeName,
                        specimenTypeName: t.specimenTypeName,
                        checkCategoryName: t.checkCategoryName,
                        subspecialtyTypeName: t.subspecialtyTypeName,
                        scanDefinition: t.scanDefinition,
                        biopsyQuality: t.biopsyQuality,
                        isEvaluateStatus:
                            t.isEvaluate === 0
                                ? '未评价'
                                : t.isEvaluate === 1
                                ? '已评价'
                                : '',
                        newFilename: t.newFilename,
                        originFilename: t.originFilename,
                    });
                });
                this.assessmentTable.pageInfo = res.data.pageInfo;
                this.assessmentTable.pageInfo.page += 1;
            });
            this.assessmentTable.isLoading = false;
        },
        getComposeValue(diagnosisType) {
            return diagnosisType === null
                ? ''
                : diagnosisType === 0
                ? ''
                : diagnosisType === 1
                ? '(被邀请)'
                : '';
        },
    },
};
</script>

<style scoped>
.col-button-top {
    margin-top: 6px;
}

.assess-font-color {
    color: #10a1df;
    display: inline-block;
    line-height: 40px;
}

.expansion {
    width: 30px;
    height: 30px;
    display: inline;
    font-size: 28px;
    line-height: 30px;
    margin-top: 25px;
    vertical-align: middle;
    color: #10a1df;
    cursor: pointer;
}
</style>
